package com.latvia.ui;

import java.util.ArrayList;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import com.latvia.cookingapp.R;
import com.latvia.cookingapp.ViewRecipeActivity;
import com.latvia.managers.DataManager;
import com.latvia.model.Recipe;

public class FavouritesFragment extends Fragment {

	private ListView recipesListView;
	

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		View layout = inflater.inflate(R.layout.favourites_fragment, container,
				false);
		recipesListView = (ListView) layout.findViewById(R.id.recipesListView);
		ArrayList<Recipe> recipes = DataManager.getInstance().getFavouriteRecipes();
		RecipesListViewAdapter recipeListVA = new RecipesListViewAdapter(
				getActivity(), recipes );
		recipesListView.setAdapter(recipeListVA);
		recipesListView
				.setOnItemClickListener(new AdapterView.OnItemClickListener() {
					@Override
					public void onItemClick(AdapterView<?> parent,
							View itemClicked, int position, long id) {
						
						 Intent myIntent = new Intent(getActivity(), ViewRecipeActivity.class);
						   getActivity().startActivity(myIntent);

//						Toast.makeText(getActivity(), "Favourites",
//								Toast.LENGTH_SHORT).show();

					}
				});
		return layout;
	}

}
